package LambdaDemo;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo {
    public static void main(String[] args) {
        String digits = "23";
        List<String> list = letterCombinations(digits);
        System.out.println(list);
//        char c1 = 'a';
//        char c2 = 'b';
//        System.out.println(c1==c2);
//        ArrayList<String> list = new ArrayList<String>();
//
//        list.add("林青霞");
//        list.add("张曼玉");
//        list.add("王祖贤");
//        list.add("柳岩");
//        list.add("张敏");
//        list.add("张无忌");


        //list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3).forEach(s -> System.out.println(s));
//        list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3).forEach(System.out :: println);
//        list.stream().filter(s->s.startsWith("张")).filter(s->s.length() == 3).forEach(System.out::println);
//        list.stream().skip(3).forEach(System.out::println);
//        System.out.println("---------");
//        list.stream().limit(3).forEach(System.out::println);
//        System.out.println("-----------");
//        list.stream().skip(2).limit(2).forEach(System.out::println);

//        List<String> list = new ArrayList<>();
//        list.add("10");
//        list.add("5");
//        list.add("20");
//        list.add("30");
//        list.add("40");
//        list.add("50");

//        Stream<String> stream1 = list.stream().limit(4);
//        Stream<String> stream2 = list.stream().skip(2);
////        Stream.concat(stream1,stream2).forEach(System.out::println);
//        Stream.concat(stream1,stream2).distinct().forEach(System.out::println);

//        list.stream().sorted().forEach(System.out::println);
//        System.out.println("-----------");
////        list.stream().sorted((s1,s2)-> s1.length() - s2.length()).forEach(System.out::println);
//        list.stream().sorted((s1,s2)->{
//            int num = s1.length() - s2.length();
//            int num2 = num==0?s1.compareTo(s2):num;
//            return num2;
//        }).forEach(System.out::println);

//        list.stream().map(Integer::parseInt).forEach(System.out::println);
//        int sum = list.stream().mapToInt(Integer::parseInt).sum();
//        System.out.println(sum);

//        List<String> names = list.stream().filter(s -> s.length() == 3).collect(Collectors.toList());
//        for(String name : names){
//            System.out.println(name);
//
//        }
//        int[] nums = new int[]{-1,0,1,2,-1,-4};
//        List<List<Integer>> list = new ArrayList<>();
//        list = threeSum(nums);
//        System.out.println(list);
    }
    public static List<List<Integer>> threeSum(int[] nums) {
        Arrays.sort(nums);
        int len = nums.length;
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> temp = new ArrayList<>();
        for(int i = 0;i<len;i++){
            if(nums[i] > 0) return res;
            int left = i+1;
            int right = nums.length-1;
            if(i>0&&nums[i-1] == nums[i]) continue;
            while(left < right){
                if(nums[i] + nums[left] +nums[right]==0){
                    temp.add(nums[i]);
                    temp.add(nums[left]);
                    temp.add(nums[right]);
                    res.add(temp);
                    while(left < right && nums[left] == nums[left+1]) left++;
                    while(left < right && nums[right] == nums[right-1]) right--;
                    left++;
                    right--;
                }else if(nums[i] + nums[left] +nums[right]<0){
                    left++;
                }else{
                    right--;
                }
                temp.clear();
            }

        }
        return res;
    }

    public static List<String> letterCombinations(String digits){
        List<String> res = new ArrayList<>();
        if(digits.length() == 0 || digits==null) return res;
        int len = digits.length();
        String[] strs = new String[]{"","*","abc","def","ghi","jkl","mno","pqrs","tuv", "wxyz"};
        res.add("");
        for(int i = 0;i<len;i++){
            String temp1 = strs[digits.charAt(i) - '0'];
            int size = res.size();
            for(int j = 0;j<size;j++){
                String temp2 = res.remove(0);
                for(int k = 0;k<temp1.length();k++){
                    res.add(temp2+temp1.charAt(k));
                }
            }
        }
        return res;
    }
}
